<!-- 会员编辑弹窗 -->
<template>
  <el-dialog
    width="1250px"
    :visible="visible"
    :lock-scroll="false"
    :destroy-on-close="true"
    custom-class="ele-dialog-form"
    :title="isUpdate?'申请提现':'申请提现'"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="132px">
      <el-form-item label="可提现总额" prop="price">
        <el-input
          clearable
          :maxlength="20"
          disabled=“disabled”
          v-model="form.price"
          placeholder="总金额"/>
      </el-form-item>

      <el-form-item label="提现金额" prop="ti_price">
        <el-input
          clearable
          :maxlength="20"
          disabled=“disabled”
          v-model="form.ti_price"
          placeholder="提现金额"/>
      </el-form-item>

      <el-form-item label="提现方式" prop="type">
        <el-radio-group
          v-model="form.type">
          <el-radio :label="1">微信</el-radio>
          <el-radio :label="2">支付宝</el-radio>
          <el-radio :label="3">银行卡</el-radio>
        </el-radio-group>
      </el-form-item>
      <div :style="form.type == 1  ?'display: block':'display: none'">
        <el-form-item label="微信号" prop="wechat">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.wechat"
            placeholder="微信号"/>
        </el-form-item>
        <el-form-item label="收款人" prop="name">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.name"
            placeholder="收款人姓名"/>
        </el-form-item>
      </div>
      <div :style="form.type == 2  ?'display: block':'display: none'">
        <el-form-item label="支付宝账号" prop="alipay">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.alipay"
            placeholder="支付宝账号"/>
        </el-form-item>
        <el-form-item label="收款人" prop="name">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.name"
            placeholder="收款人姓名"/>
        </el-form-item>
      </div>
      <div :style="form.type == 3  ?'display: block':'display: none'">
        <el-form-item label="银行卡号" prop="alipay">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.alipay"
            placeholder="银行卡号"/>
        </el-form-item>
        <el-form-item label="收款人" prop="name">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.name"
            placeholder="收款人姓名"/>
        </el-form-item>
        <el-form-item label="收款开户行" prop="bank">
          <el-input
            clearable
            :maxlength="20"
            v-model="form.bank"
            placeholder="收款开户行"/>
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer">
      <el-button
        @click="updateVisible(false)">取消
      </el-button>
      <el-button
        type="primary"
        :loading="loading"
        @click="save">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>

import uploadImage from '@/components/uploadImage'
import '@riophae/vue-treeselect/dist/vue-treeselect.css';
import TinymceEditor from '@/components/TinymceEditor';
import Treeselect from '@riophae/vue-treeselect';
import '@riophae/vue-treeselect/dist/vue-treeselect.css';

export default {
  name: 'MemberEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object,
    // 栏目数据
    cateList: Array
  },
  components: {uploadImage, TinymceEditor, Treeselect},
  data() {
    return {


      // 表单数据
      form: Object.assign({}, ''),
      rules: {
        ti_price: [
          {required: true, message: '请输入提现金额', trigger: 'blur'}
        ],
        type: [
          {required: true, message: '请选择提现方式', trigger: 'blur'}
        ],
      },
      // 表单验证规则

      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      // 会员等级列表

      labelList: [],
      packageList: [],


      is_time: 1,

    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data, {
          price: this.data.price,
          ti_price: this.data.price,
          m_price: this.data.m_price,
        });


        this.isUpdate = true;
      } else {
        this.form = {};
        this.form.is_time = 1;
        this.isUpdate = false;
      }
    }
  },


  mounted() {
    // 获取职级列表
    this.getStoreInfo();


  },
  methods: {

    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          // 城市数据处理

          this.$http.post('/cash/edit', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message({type: 'success', message: res.data.msg});
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },

    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    },


    getStoreInfo() {
      this.$http.get('/cash/getStoreInfo').then(res => {
        if (res.data.code === 0) {
          this.price = res.data.data;
          console.log(res.data.data)
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch(e => {
        this.$message.error(e.message);
      });
    },

  }
}
</script>

<style scoped>
</style>
